using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace Catastrophe.Log
{
	public class BaseLog
	{
		public LogTypeEnum LogType { get; set; }

		public string SoftId { get; set; }

		public BaseLog(LogTypeEnum? logType = null)
		{
			if (logType.HasValue)
			{
				this.LogType = logType.Value;
			}
		}

		public SysLogEntity GetExEntity(LogLevelEnum logType, string defineMsg, Exception ex)
		{
			List<ExceptionDetails> item = ExceptionUtil.ExceptionFormat(ex).Item2;
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = new StringBuilder();
			StringBuilder stringBuilder3 = new StringBuilder();
			foreach (ExceptionDetails item2 in item)
			{
				stringBuilder.Append(item2.Message + Environment.NewLine);
				stringBuilder2.Append(item2.StackTrace + Environment.NewLine);
				stringBuilder3.Append(item2.TargetSite + Environment.NewLine);
			}
			SysLogEntity sysLogEntitycs = new SysLogEntity();
			sysLogEntitycs.ExMsg = stringBuilder.ToString().TrimEnd('\r', '\n');
			sysLogEntitycs.StackTrace = stringBuilder2.ToString().TrimEnd('\r', '\n');
			sysLogEntitycs.TargetSite = stringBuilder3.ToString().TrimEnd('\r', '\n');
			sysLogEntitycs.SoftId = this.SoftId;
			SysLogEntity sysLogEntitycs2 = sysLogEntitycs;
			object obj = (ex?.GetType().GetProperty("HResult"))?.GetValue(ex, new object[0]);
			if (obj != null)
			{
				sysLogEntitycs2.ErrorCode = obj.ToString();
			}
			sysLogEntitycs2.DefineMsg = defineMsg;
			sysLogEntitycs2.ErrorLevel = logType.ToString();
			return sysLogEntitycs2;
		}

		public string GetExStr(LogLevelEnum logType, string defineMsg, Exception ex)
		{
			object obj = (ex?.GetType().GetProperty("HResult"))?.GetValue(ex, new object[0]);
			string value = "未知";
			if (obj != null)
			{
				value = obj.ToString();
			}
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(46, 7);
			defaultInterpolatedStringHandler.AppendLiteral("异常等级：");
			defaultInterpolatedStringHandler.AppendFormatted(logType);
			defaultInterpolatedStringHandler.AppendLiteral("\r\n");
			defaultInterpolatedStringHandler.AppendLiteral("自定义消息：");
			defaultInterpolatedStringHandler.AppendFormatted(defineMsg);
			defaultInterpolatedStringHandler.AppendLiteral("\r\n");
			defaultInterpolatedStringHandler.AppendLiteral("异常编码：");
			defaultInterpolatedStringHandler.AppendFormatted(value);
			defaultInterpolatedStringHandler.AppendLiteral("\r\n");
			defaultInterpolatedStringHandler.AppendLiteral("异常消息：");
			defaultInterpolatedStringHandler.AppendFormatted(ex?.Message);
			defaultInterpolatedStringHandler.AppendLiteral("\r\n");
			defaultInterpolatedStringHandler.AppendLiteral("异常位置：");
			defaultInterpolatedStringHandler.AppendFormatted(ex?.StackTrace);
			defaultInterpolatedStringHandler.AppendLiteral("\r\n");
			defaultInterpolatedStringHandler.AppendLiteral("异常方法：");
			defaultInterpolatedStringHandler.AppendFormatted(ex?.TargetSite);
			defaultInterpolatedStringHandler.AppendLiteral("\r\n");
			defaultInterpolatedStringHandler.AppendLiteral("时间：");
			defaultInterpolatedStringHandler.AppendFormatted(DateTime.Now, "yyyy/MM/dd HH:mm:ss");
			return defaultInterpolatedStringHandler.ToStringAndClear();
		}
	}
}
